package com.burpee.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.burpee.service.BoardService;
import com.burpee.service.CoordinateService;
import com.burpee.service.ExerciseService;
import com.burpee.service.FoodService;
import com.burpee.service.MemberService;
import com.burpee.ui.Board;
import com.burpee.ui.Exercise;
import com.burpee.ui.Food;
import com.burpee.ui.Member;


@Controller
@RequestMapping("/admin.spring")
public class AdminController {
	
	@Autowired
	MemberService memberService;
	
	@Autowired
	ExerciseService exerciseService;
	
	@Autowired
	FoodService foodService;
	
	@Autowired
	BoardService boardService;
	
	@Autowired
	CoordinateService coordinateService;
	
	
	
	@RequestMapping(params = "action=home")
	public ModelAndView home(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("redirect:main.spring");
		return modelAndView;
	}
	
	
	
	
	@RequestMapping(params = "action=adminMode")
	public ModelAndView adminMode(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminMain");
		return modelAndView;
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////회원 관리///////////////////////////////////////////////////////////////////////////
	@RequestMapping(params = "action=adminMemberSide")
	public ModelAndView adminMember(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminMemberSide");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminmemberSearch")
	public ModelAndView adminmemberSearch(HttpServletRequest request, HttpServletResponse response) {
		
		List<Member> memberList =  memberService.list();
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("memberList", memberList);
		
		modelAndView.setViewName("admin/adminMember");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminMemberLevel")
	public ModelAndView adminMemberLevel(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminMemberLevel");
		return modelAndView;
	}

	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////운동 관리///////////////////////////////////////////////////////////////////////////
	
	@RequestMapping(params = "action=adminExerciseSide")
	public ModelAndView adminExercise(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminExerciseSide");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminExerciseAdd")
	public ModelAndView adminExerciseAdd(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminExerciseAdd");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminExerciseList")
	public ModelAndView adminExerciseList(HttpServletRequest request, HttpServletResponse response) {
		
		List<Exercise> exercise = exerciseService.adminList();
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("exercise", exercise);
		modelAndView.setViewName("admin/adminExerciseList");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminExercisePreModify")
	public ModelAndView adminExercisePreModify(HttpServletRequest request, HttpServletResponse response, Exercise exercise) {
		
		exercise = exerciseService.view(exercise.getExerciseNo());
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("exercise", exercise);
		modelAndView.setViewName("admin/adminExerciseModify");
		return modelAndView;
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////음식 관리///////////////////////////////////////////////////////////////////////////	
	@RequestMapping(params = "action=adminFoodSide")
	public ModelAndView adminFood(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminFoodSide");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminFoodList")
	public ModelAndView adminFoodList(HttpServletRequest request, HttpServletResponse response) {
		
		List<Food> food = foodService.list();
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("food", food);
		modelAndView.setViewName("admin/adminFoodList");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminFoodPreAdd")
	public ModelAndView adminFoodPreAdd(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminFoodAdd");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminFoodPreModify")
	public ModelAndView adminFoodPreModify(HttpServletRequest request, HttpServletResponse response, Food food ) {
		
		food = foodService.view(food.getFoodNo());
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("food", food);
		modelAndView.setViewName("admin/adminFoodModify");
		return modelAndView;
	}

	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////그룹 관리///////////////////////////////////////////////////////////////////////////
	@RequestMapping(params = "action=adminGroupSide")
	public ModelAndView adminGroup(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminGroupSide");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminHealthcareSide")
	public ModelAndView adminHealthcare(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminHealthcareSide");
		return modelAndView;
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////게시판 관리///////////////////////////////////////////////////////////////////////////
	@RequestMapping(params = "action=adminBoardSide")
	public ModelAndView adminBoard(HttpServletRequest request, HttpServletResponse response) {

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminBoardSide");
		return modelAndView;
	}

	@RequestMapping(params = "action=adminBoardList")
	public ModelAndView adminBoardList(HttpServletRequest request, HttpServletResponse response) {

		List<Board> board = boardService.list();

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("board", board);
		modelAndView.setViewName("admin/adminBoardList");
		return modelAndView;
	}

	@RequestMapping(params = "action=adminBoardPreAdd")
	public ModelAndView adminBoardPreAdd(HttpServletRequest request, HttpServletResponse response) {

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminBoardAdd");
		return modelAndView;
	}
	@RequestMapping(params = "action=adminBoardAdd")
	public ModelAndView adminBoardAdd(HttpServletRequest request, HttpServletResponse response, Board board) {

		boardService.add(board);

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminBoardAdd");
		return modelAndView;
	}

	@RequestMapping(params = "action=adminBoardPreModify")
	public ModelAndView adminBoardPreModify(HttpServletRequest request, HttpServletResponse response, Board board ) {

		board = boardService.view(board.getBoardNo());

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("board", board);
		modelAndView.setViewName("admin/adminBoardModify");
		return modelAndView;
	}
	@RequestMapping(params = "action=adminBoardModify")
	public ModelAndView adminBoardModify(HttpServletRequest request, HttpServletResponse response, Board board){

	   boardService.modify(board);
				
				
	   ModelAndView modelAndView = new ModelAndView();
	   modelAndView.setViewName("admin/adminBoardList");
	   return modelAndView;
	}
	@RequestMapping(params = "action=adminBoardRemove")
	public ModelAndView remove(HttpServletRequest request, HttpServletResponse response, Board boardre){
		
		boardService.remove(boardre.getBoardNo());
		
		List<Board> board = boardService.list();

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("board", board);
		modelAndView.setViewName("admin/adminBoardList");
		return modelAndView;
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////위치 표시 관리///////////////////////////////////////////////////////////////////////////
	
	@RequestMapping(params = "action=adminLocationSide")
	public ModelAndView adminLocation(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminLocationSide");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminLocationAdd")
	public ModelAndView adminLocationAdd(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminLocationAdd");
		return modelAndView;
	}
	
	@RequestMapping(params = "action=adminLocationMap")
	public ModelAndView adminLocationMap(HttpServletRequest request, HttpServletResponse response) {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("admin/adminLocationMap");
		return modelAndView;
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////게시판 관리///////////////////////////////////////////////////////////////////////////
	
	
}
